﻿@model IEnumerable<MVC_Store.Models.ViewModels.Shop.ProductVM>

@{
    ViewBag.Title = "Products";
}

@using PagedList.Mvc;
@using PagedList;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

<h2>Products</h2>

<select id="SelectCategory" name="SelectCategory">
    <option value="0">All</option>
    @foreach (var item in ViewBag.Categories)
    {
        if (ViewBag.SelectedCat == item.Value)
        {
            <option selected="selected" value="@item.Value">@item.Text</option>
        }
        else
        {
            <option value="@item.Value">@item.Text</option>
        }
    }
</select>
<br /><br />

<p>
    @Html.ActionLink("Add new product", "AddProduct", "", new { @class = "btn btn-success" })
</p>
<table class="table">
    <tr>
        <th>
            Name
        </th>

        <th>
            Description
        </th>
        <th>
            Price
        </th>

        <th>
            Image
        </th>
        <th></th>
    </tr>

    @foreach (var product in ViewBag.OnePageOfProducts)
    {
        <tr>
            <td>
                @product.Name
            </td>

            <td>
                @product.Description
            </td>

            <td>
                @product.Price
            </td>

            <td>
                <a href="/admin/shop/EditProduct/@product.Id">
                    @if (@product.ImageName == null)
                    {
                        <img src="/Content/img/no_image.png" />
                    }
                    else
                    {
                        <img src="/Images/Uploads/Products/@product.Id/Thumbs/@product.ImageName" />
                    }
                </a>
            </td>

            <td>
                @Html.ActionLink("Edit", "EditProduct", new { id = product.Id }, new { @class = "btn btn-info" }) |
                @Html.ActionLink("Delete", "DeleteProduct", new { id = product.Id }, new { @class = "btn btn-danger delete" })
            </td>
        </tr>
    }
</table>

@Html.PagedListPager((IPagedList)ViewBag.onePageOfProducts, page => Url.Action("Products", new { page, catId = ViewBag.SelectedCat }))

@section Scripts
{
    <script src="~/Content/ShopJS/ProductsScript.js"></script>
}